Skip to content

Conversation

stevendanna
Copy link
Collaborator

@stevendanna stevendanna commented Aug 15, 2025

To reduce the number of batches, we'd like to piggy-back our buffer
flush on the user-provided batch. But, in some cases this is problematic
as the user may have set options on the batch that can result in the
batch being incompletely processed. Here, we check for those options and
flush the buffer via a sanitized batch before processing the user's
batch.

In a follow-up, we may also always use a separate batch for midTxn
flushes to avoid nearly all read-write batches.

Epic: None
Release note: None

Copy link

blathers-crl bot commented Aug 15, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@stevendanna stevendanna force-pushed the ssd/txn-wb-split-batch branch from 58864dc to cba48b8 Compare August 28, 2025 11:20
// TestBatchHeaderFieldsAreAccountedForInBufferedWrites checks that any new
// fields added to the batch header are appropriately accounted for by the
// needed functions.
func TestBatchHeaderFieldsAreAccountedForInBufferedWrites(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miraradeva What do you think about this as a way to try to keep this from drifting over time?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems reasonable. These types of tests have def saved me before. Hurray for unit tests as documentation.

@stevendanna stevendanna force-pushed the ssd/txn-wb-split-batch branch 2 times, most recently from f95e66b to fe24e41 Compare September 1, 2025 12:23
@stevendanna stevendanna changed the title WIP kvcoord: avoid piggybacking on any early-returning batch kvcoord: avoid piggybacking on any early-returning batch Sep 1, 2025
@stevendanna stevendanna marked this pull request as ready for review September 1, 2025 15:52
@stevendanna stevendanna requested a review from a team as a code owner September 1, 2025 15:52
To reduce the number of batches, we'd _like_ to piggy-back our buffer
flush on the user-provided batch. But, in some cases this is problematic
as the user may have set options on the batch that can result in the
batch being incompletely processed. Here, we check for those options and
flush the buffer via a sanitized batch before processing the user's
batch.

In a follow-up, we may also _always_ use a separate batch for midTxn
flushes to avoid nearly all read-write batches.

Epic: None
Release note: None
Informs #Fixes

Epic: none
Release note: None
@stevendanna stevendanna force-pushed the ssd/txn-wb-split-batch branch from fe24e41 to 5e2a418 Compare September 4, 2025 08:50
@stevendanna
Copy link
Collaborator Author

Test failure looks unrelated.

Copy link
Contributor

@miraradeva miraradeva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: But I don't have very high confidence in whether each individual field in the header is ok or not.

@miraradeva reviewed 2 of 4 files at r1, 2 of 2 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @stevendanna)


pkg/kv/kvclient/kvcoord/txn_interceptor_write_buffer.go line 1774 at r3 (raw file):

	midTxnFlush := !hasEndTxn
	splitBatchRequired := separateBatchIsNeeded(ba) // || midTxnFlush

nit: remove comment?


pkg/kv/kvclient/kvcoord/txn_interceptor_write_buffer.go line 1819 at r3 (raw file):

		clearBatchRequestOptions(flushBatch)
		flushBatch.Requests = reqs
		log.VEventf(ctx, 2, "flushing %d buffered requests via separate batch", len(reqs))

Is it useful to log the full batch, in case we need to debug header field values?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants